package com.lotus.tep.ui;

import chrriis.dj.nativeswing.swtimpl.components.JWebBrowser;
import com.lotus.tep.constant.BrowserEmbededFrameConstant;
import com.lotus.tep.constant.UrlConstant;
import com.lotus.tep.constant.WebBrowserConstant;
import com.lotus.tep.event.LiteToiArticleWindowHandler;
import com.lotus.tep.event.MmArticleWindowHandler;
import com.lotus.tep.event.ToiArticleWindowHandler;
import javax.swing.JInternalFrame;

public class BrowserEmbededFrame extends JInternalFrame {

	private JWebBrowser jWebBrowser_;

	public BrowserEmbededFrame() {
		super(BrowserEmbededFrameConstant.TITLE, BrowserEmbededFrameConstant.RESIZABLE, BrowserEmbededFrameConstant.CLOSEABLE, BrowserEmbededFrameConstant.MAXIMIZABLE, BrowserEmbededFrameConstant.ICONABLE);
		jWebBrowser_ = new JWebBrowser(JWebBrowser.destroyOnFinalization());
	}

	public void build() {
		setBounds(BrowserEmbededFrameConstant.X, BrowserEmbededFrameConstant.Y, BrowserEmbededFrameConstant.WIDTH, BrowserEmbededFrameConstant.HEIGHT);
		jWebBrowser_.setMenuBarVisible(WebBrowserConstant.MENU_BAR_VISIBLE);
		jWebBrowser_.setLocationBarVisible(WebBrowserConstant.ADDRESS_BAR_VISIBLE);
		jWebBrowser_.setJavascriptEnabled(WebBrowserConstant.JS_ENABLED);
		jWebBrowser_.navigate(UrlConstant.EPAPER_HOME_PAGE_URL);
		add(jWebBrowser_);
		jWebBrowser_.setDefaultPopupMenuRegistered(WebBrowserConstant.POPUP_MENU_ENABLED);
		jWebBrowser_.addWebBrowserListener(new LiteToiArticleWindowHandler());
		jWebBrowser_.addWebBrowserListener(new ToiArticleWindowHandler());
		jWebBrowser_.addWebBrowserListener(new MmArticleWindowHandler());
		setVisible(BrowserEmbededFrameConstant.VISIBLE);
	}

	public JWebBrowser getJWebBrowser() {
		return jWebBrowser_;
	}

	@Override
	public int getLayer() {
		return BrowserEmbededFrameConstant.LAYER_INDEX;
	}
}
